{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 连接"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from aip import AipNlp\n",
    "\n",
    "\"\"\" 你的 APPID AK SK \"\"\"\n",
    "APP_ID = ''\n",
    "API_KEY = ''\n",
    "SECRET_KEY = ''\n",
    "\n",
    "client = AipNlp(APP_ID, API_KEY, SECRET_KEY)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'log_id': 4145184841870738294, 'text': '百度是一家高科技公司', 'items': [{'loc_details': [], 'byte_offset': 0, 'uri': '', 'pos': '', 'ne': 'ORG', 'item': '百度', 'basic_words': ['百度'], 'byte_length': 4, 'formal': ''}, {'loc_details': [], 'byte_offset': 4, 'uri': '', 'pos': 'v', 'ne': '', 'item': '是', 'basic_words': ['是'], 'byte_length': 2, 'formal': ''}, {'loc_details': [], 'byte_offset': 6, 'uri': '', 'pos': 'm', 'ne': '', 'item': '一家', 'basic_words': ['一', '家'], 'byte_length': 4, 'formal': ''}, {'loc_details': [], 'byte_offset': 10, 'uri': '', 'pos': 'n', 'ne': '', 'item': '高科技', 'basic_words': ['高', '科技'], 'byte_length': 6, 'formal': ''}, {'loc_details': [], 'byte_offset': 16, 'uri': '', 'pos': 'n', 'ne': '', 'item': '公司', 'basic_words': ['公司'], 'byte_length': 4, 'formal': ''}]}\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[{'basic_words': ['百度'],\n",
       "  'byte_length': 4,\n",
       "  'byte_offset': 0,\n",
       "  'formal': '',\n",
       "  'item': '百度',\n",
       "  'loc_details': [],\n",
       "  'ne': 'ORG',\n",
       "  'pos': '',\n",
       "  'uri': ''},\n",
       " {'basic_words': ['是'],\n",
       "  'byte_length': 2,\n",
       "  'byte_offset': 4,\n",
       "  'formal': '',\n",
       "  'item': '是',\n",
       "  'loc_details': [],\n",
       "  'ne': '',\n",
       "  'pos': 'v',\n",
       "  'uri': ''},\n",
       " {'basic_words': ['一', '家'],\n",
       "  'byte_length': 4,\n",
       "  'byte_offset': 6,\n",
       "  'formal': '',\n",
       "  'item': '一家',\n",
       "  'loc_details': [],\n",
       "  'ne': '',\n",
       "  'pos': 'm',\n",
       "  'uri': ''},\n",
       " {'basic_words': ['高', '科技'],\n",
       "  'byte_length': 6,\n",
       "  'byte_offset': 10,\n",
       "  'formal': '',\n",
       "  'item': '高科技',\n",
       "  'loc_details': [],\n",
       "  'ne': '',\n",
       "  'pos': 'n',\n",
       "  'uri': ''},\n",
       " {'basic_words': ['公司'],\n",
       "  'byte_length': 4,\n",
       "  'byte_offset': 16,\n",
       "  'formal': '',\n",
       "  'item': '公司',\n",
       "  'loc_details': [],\n",
       "  'ne': '',\n",
       "  'pos': 'n',\n",
       "  'uri': ''}]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text = \"百度是一家高科技公司\"\n",
    "\n",
    "\"\"\" 调用词法分析 \"\"\"\n",
    "#这个竟然是dict格式\n",
    "dict=client.lexer(text)\n",
    "print(client.lexer(text))\n",
    "#调用\n",
    "dict[\"items\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'log_id': 8247720452417727094, 'items': [{'loc_details': [], 'byte_offset': 0, 'uri': '', 'ne': 'ORG', 'basic_words': ['百度'], 'item': '百度', 'pos': '', 'byte_length': 4, 'formal': ''}, {'loc_details': [], 'byte_offset': 4, 'uri': '', 'ne': '', 'basic_words': ['是'], 'item': '是', 'pos': 'v', 'byte_length': 2, 'formal': ''}, {'loc_details': [], 'byte_offset': 6, 'uri': '', 'ne': '', 'basic_words': ['一', '家'], 'item': '一家', 'pos': 'm', 'byte_length': 4, 'formal': ''}, {'loc_details': [], 'byte_offset': 10, 'uri': '', 'ne': '', 'basic_words': ['高', '科技'], 'item': '高科技', 'pos': 'n', 'byte_length': 6, 'formal': ''}, {'loc_details': [], 'byte_offset': 16, 'uri': '', 'ne': '', 'basic_words': ['公司'], 'item': '公司', 'pos': 'n', 'byte_length': 4, 'formal': ''}], 'text': '百度是一家高科技公司'}\n"
     ]
    }
   ],
   "source": [
    "text = \"百度是一家高科技公司\"\n",
    "\n",
    "\"\"\" 调用词法分析（定制版） \"\"\"\n",
    "print(client.lexerCustom(text))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'items': [{'deprel': 'HED',\n",
       "   'head': 0,\n",
       "   'id': 1,\n",
       "   'postag': 'nr',\n",
       "   'word': '张飞'}],\n",
       " 'log_id': 2878418531490766262,\n",
       " 'text': '张飞'}"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text = \"张飞\"\n",
    "\n",
    "\"\"\" 调用依存句法分析 \"\"\"\n",
    "client.depParser(text);\n",
    "\n",
    "\"\"\" 如果有可选参数 \"\"\"\n",
    "options = {}\n",
    "options[\"mode\"] = 1\n",
    "\n",
    "\"\"\" 带参数调用依存句法分析 \"\"\"\n",
    "client.depParser(text, options)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'log_id': 2372168629102950646, 'word': '张飞', 'vec': [-0.290384, -0.276273, 0.302719, 0.7209, 0.108958, 0.553115, -0.0877021, 0.359806, 0.0880146, -0.189588, 0.244222, -0.0651301, 0.0638421, 0.533272, -0.00821664, 0.0375696, -0.327892, -0.46532, 0.865607, 0.623493, -0.178252, -0.0400714, 0.25975, 0.11109, 0.0953429, 0.101911, -0.535927, -0.0933478, 0.601825, -0.321298, 0.631975, 0.0875886, 0.870735, -0.269735, -0.585102, 0.319081, 0.184684, -0.720537, -0.383718, -0.0765072, 0.31901, 0.270633, 0.795086, -0.203823, -0.125412, 0.45416, -0.172919, 0.295541, -0.216173, -0.430564, 0.0180166, 0.138979, -0.277238, 0.741072, 0.190484, -0.030923, -0.0943274, 0.591492, -0.418138, -0.523783, -0.227849, 0.366404, -0.443689, -0.125983, 0.0810465, -0.40937, -0.1809, -0.391663, 0.184682, 0.176599, 0.296323, 0.263794, 0.148703, 0.121896, 0.267335, -0.20897, -0.000618858, -0.258487, 0.284275, 0.115589, -0.28355, 0.150706, -0.220889, -0.591039, 0.0290777, -0.201643, 0.0797944, 0.488941, 0.831331, -0.379756, -0.139497, 0.2703, 0.504657, -0.440968, -0.1447, -0.110457, -0.0163559, 0.767792, 0.491371, -0.549788, 0.205589, 0.362547, 0.445447, 0.114256, -0.390303, 0.355757, -0.35865, 0.309228, -0.0702368, 0.0218542, -0.20673, 0.18002, 0.0739457, 0.230891, 0.014336, 0.18294, 0.660368, 0.771709, 0.210481, -0.366585, -0.487737, -0.392698, 0.165913, 0.0634584, 0.327222, 0.170312, 0.16333, -0.0126046, 0.139614, 0.41918, -0.151494, 0.317118, -0.391317, -0.673394, -0.430471, 0.0830508, -0.270076, 0.336409, -0.218263, 0.417467, 0.595822, -0.114509, 0.323514, 0.405187, -0.144482, -0.179517, 0.185674, -0.161061, 0.0338107, -0.290429, -0.187511, 0.131024, 0.0655593, -0.0429835, 0.249348, 0.470223, 0.439866, 0.191249, -0.551478, -0.0530808, 0.220113, 0.21264, 0.4053, 0.000986318, 0.431895, -0.266691, 0.387755, -0.176948, 0.790972, -0.186954, 0.311339, -0.847612, 0.0591855, 0.217022, -0.40963, 0.0388994, 0.258638, -0.0700524, -0.517052, 0.0738539, -0.0278234, -0.0207165, -0.64623, -0.397078, -0.512611, 0.240432, 0.631851, -0.266089, 0.23193, -0.335795, 0.48978, 0.101472, 0.112899, 0.0119656, 0.205143, 0.59687, -0.139228, 0.2366, -0.0448019, -0.463323, 0.136911, 0.245667, -0.531107, -0.203959, 0.437006, 0.0385832, -0.475222, 0.152122, -0.183256, 0.147781, 0.976636, -0.268798, 0.0467436, 0.398612, 0.726595, 0.0641848, 0.442981, 0.392992, 0.277279, 0.191023, 0.540712, 0.041807, 0.521223, 0.494714, -0.114315, -0.623037, 0.503307, 0.16223, -0.0109138, -0.0030869, -0.0127418, 0.0324629, 0.257331, -0.724175, 0.071035, 0.293041, -0.142676, 0.216268, 0.217721, 0.150594, 0.524261, 0.136377, -0.26703, 0.143736, 0.377088, 0.0852308, -0.248864, -0.2864, 0.336949, 0.0106289, 0.142447, 0.0830073, 0.00827009, 0.170654, -0.0537858, 0.66666, -0.167388, -0.00478372, 0.370992, -0.420722, -0.0163072, -0.224316, 0.900274, -0.0618271, 0.0933983, -0.138376, 0.0352047, 0.133874, -0.274968, -0.1037, 0.056145, 0.283046, -0.222181, 0.0843009, 0.201509, 0.0759472, 0.430465, 0.279714, -0.0762712, 0.0291045, 0.0666021, 0.389999, -0.0268815, 0.35655, 0.167335, 0.555981, 0.277015, 0.370779, -0.249201, -0.153099, 0.15063, 0.59068, 0.144961, -0.36857, 0.38433, -0.627967, 0.460143, 0.207135, -0.270095, -0.175896, 0.132773, 0.260412, -0.0316362, -0.511945, -0.014644, -0.338383, 0.513172, 0.273772, -0.245957, -0.484812, 0.479638, -0.781593, -0.692486, 0.269043, 0.48944, 0.151724, -0.109521, 0.0716606, 0.454819, -0.641453, -0.28264, -0.0844294, 0.0127063, -0.0473483, -0.0599927, 0.0715608, -0.562256, 0.215818, -0.207625, -0.0960898, 0.0344254, -0.0852497, -0.119984, 0.296039, -0.595229, 0.253829, -0.111723, 0.411277, 0.101737, -0.0322796, 0.345638, 0.0965107, 0.083087, 0.291633, -0.091778, -0.0279783, -0.108174, -0.300271, -0.541914, 0.197143, 0.631338, 0.479441, 0.0369768, 0.451288, -0.127012, -0.639879, 0.0512995, 0.273387, -0.418342, -0.45064, -0.1239, -0.595654, 0.31378, -0.35008, -0.0134738, 0.476063, 0.0309964, -0.0264222, -0.4704, 0.201462, 0.967353, -0.0587739, -0.221851, -0.221493, -0.319194, 0.321394, 0.176416, 0.0173751, -0.0174415, 0.339173, -0.0516278, -0.255842, -0.283161, -0.017094, -0.138473, 0.271638, 0.496162, 0.519359, -0.00602108, 0.459303, 0.295921, 0.27062, 0.753482, 0.0583323, 0.181312, -0.106313, 0.646242, -0.00311025, -0.163957, 0.182659, -0.0996339, 0.272461, 0.301206, 0.35085, 0.37463, -0.155242, 0.281236, -0.294234, 0.00533482, -0.00310824, 0.0731524, -0.394956, 0.452704, 0.000153456, -0.0800992, -0.0785606, -0.439399, -0.575366, -0.216206, -0.212303, -0.624662, 0.0487097, -0.15867, 0.278319, -0.21006, 0.786678, 0.23844, 0.189342, 0.108299, -0.511393, 0.405482, -0.161949, 0.212671, -0.379168, -0.0637337, 0.13583, 0.0522022, 0.072762, -0.11513, -0.647886, 0.112957, 0.147099, -0.156163, -0.127035, 0.145647, 0.182698, 0.482085, -0.0702394, -0.0172681, -0.24563, -0.0392392, -0.491031, -0.19934, 0.132408, 0.285179, 0.40498, 0.134263, 0.262012, 0.142867, -0.147229, -0.268257, 0.1726, 0.476211, -0.836967, 0.568796, 0.077607, -0.510508, 0.0675741, -0.681589, 0.100888, -0.326709, 0.266345, -0.397411, -0.644215, -0.13274, -0.354817, -0.558334, -0.114178, -0.0940336, 0.235152, -0.554642, 0.382976, -0.274543, -0.105513, -0.409024, -0.0281389, -0.350335, -0.773656, 0.602614, 0.0406916, -0.566817, 0.100671, 0.0793555, 0.176259, 0.218086, 0.654524, -0.109966, 0.157835, -0.214399, 0.166806, 0.297687, -0.526347, 0.330715, -0.223834, 0.354683, 0.164879, -0.060529, 0.208646, -0.347635, -0.386788, -0.434064, -0.448538, 0.106584, -0.137211, -0.821776, 0.448596, 0.55277, -0.486275, 0.0597583, 0.108438, 0.0167387, -0.205475, -0.367478, 0.0528088, 0.191489, 0.308181, 0.124091, 0.0241138, 0.332369, -0.418433, 0.609042, -0.564987, -0.0275926, -0.190715, 0.114899, 0.0137452, 0.00163973, 0.0747787, 0.219737, 0.0336625, 0.0256406, -0.14083, -0.0510848, 0.280421, -0.0751052, -0.195839, 0.217633, -0.110681, -0.692188, -0.516287, 0.0406127, 0.514706, 0.461349, 0.31112, -0.505281, -0.209302, -0.478191, -0.159178, 0.262902, 0.215158, -0.0384547, -0.0301001, -0.68696, 0.333097, 0.387189, -0.397549, -0.389793, -0.326927, -0.426165, -0.249444, -0.287807, -0.358692, 0.344935, -0.22274, -0.12828, -0.0673532, -0.0972766, -0.227617, -0.248091, -0.0705791, 0.63178, -0.759731, -0.368149, 0.578806, 0.280523, -0.0312885, -0.516321, -0.308148, -0.463663, -1.11399, 0.299133, 0.324969, -0.0922515, -0.223782, 0.0757393, 0.0956187, 0.307651, 0.274788, -0.495276, 0.305883, 0.0228269, 0.437532, -0.260021, -0.36529, -0.122708, -0.175827, 0.146148, 0.143242, -0.142164, -0.0918094, -0.415535, -0.0301366, -0.295545, -0.618801, 0.175826, -0.756559, -0.128965, 0.0491931, 0.733814, -0.0347257, -0.460981, -0.540235, 0.138612, -0.353038, -0.0671316, 0.0149887, -0.503586, 0.0874566, 0.441919, 0.0776407, -0.272449, -0.0997288, -0.44766, -0.216144, -0.00963199, 0.0527866, -0.0218697, 0.180018, 0.164696, 0.724876, 0.136289, 0.225619, -0.161481, 0.165889, 0.857903, -0.15784, 0.186857, -0.662843, -0.558884, -0.0192077, 0.00818205, -0.0243429, -0.217057, -0.455544, 0.00163086, -0.466992, 0.113344, -0.174208, 0.251834, -0.0775733, 0.102453, 0.258227, -0.145805, 0.00610516, -0.173767, 0.129026, -0.132582, -0.148301, -0.458603, 0.367434, -0.382593, 0.116882, -0.0928457, 0.276499, 0.180621, 0.351536, 0.353009, -0.31789, -0.0245226, -0.189822, -0.705618, -0.0623819, -0.68237, 0.027945, 0.0396841, -0.081132, 0.414828, 0.251657, -0.193545, -0.0149343, 0.0925272, -0.12489, -0.458534, 0.55974, 0.277349, 0.113657, 0.574713, -0.198563, 0.905217, 0.101096, 0.0367823, -0.120045, 0.278173, -0.191525, -0.0414615, -0.105125, -0.78052, -0.448668, 0.30789, 0.497319, -0.398035, -0.55494, -0.272399, -0.102899, -0.281833, -0.262621, 0.138731, -0.444618, 0.497306, -0.275449, -0.0123345, -0.120426, 0.491484, -0.402516, -0.288962, 0.387392, -0.144125, 0.838843, -0.236083, 0.227957, 0.418015, 0.510442, 0.0841282, -0.544343, -0.0525509, -0.0398014, 0.381329, 0.281488, -0.403923, -0.210186, -0.53414, 0.0852807, -0.345891, -0.294183, 1.17415, -0.023307, -0.828112, 0.0523113, -0.0824572, 0.317031, -0.543952, -0.699134, -0.278506, -0.576854, 0.434733, -0.267847, -0.570456, -0.017377, 0.645807, -0.917205, 0.441665, -0.393248, 0.0631595, -0.386241, 0.0413631, 0.0191933, -0.474338, -0.113288, 0.400757, -0.0247571, -0.348845, -0.0123555, 0.25809, 0.427283, 0.245173, -0.294317, 0.159206, 0.118759, 0.273828, 0.643573, 0.0927131, -0.265129, 0.233232, -0.138332, -0.136015, -0.673727, 0.684253, -0.0585586, -0.327816, -0.716404, -0.58116, 0.0275417, -0.0388521, 0.0237589, -0.277684, 0.0602299, 0.209622, 0.0348703, 0.327143, 0.24981, -0.251077, -0.455329, 0.396863, -0.0570048, -0.265072, -0.0683558, 0.0132361, 0.273579, -0.366049, 0.615134, -0.103124, 0.481334, -0.746339, -0.0640788, -0.484396, -0.00114065, 0.366753, 0.0240541, 0.439156, 0.159546, -0.0506753, 0.0468946, 0.43076, 0.602602, 0.0107401, 1.19797, 0.44314, -0.698443, -0.336827, 0.0258312, 0.172399, 0.305746, -0.150144, 0.0203008, 0.326867, -0.644517, 0.0156665, 0.13351, -0.23441, -0.293748, -0.0695886, -0.477291, 0.281291, -0.755484, 0.74025, -0.552702, 0.381103, 0.164566, -0.15145, -0.728736, 0.448275, 0.0725737, 0.116212, 0.210402, 0.691626, 0.0265872, -0.448584, 0.244172, -0.245309, 0.139035, 0.0288716, -0.364476, -0.0426868, -0.21928, -0.742586, -0.0932949, -0.193005, 0.0303013, -0.76493, 0.0455655, -0.608174, 0.255099, 0.0151615, 0.0139608, 0.0158675, -0.3893, 0.373225, 0.250462, 0.0276716, -0.0752877, -0.0127418, -0.435184, -0.0627005, -0.400453, -0.147969, 0.235518, 0.181853, -0.339577, 0.553451, 0.00837407, -0.248918, -0.136399, -0.354747, -0.350052, 0.220699, -0.183795, 0.784734, 0.395384, -0.315588, 0.0276707, 0.0840118, 0.254402, 0.0226935, -0.483695, -0.075312, 0.402732, -0.0151023, 0.166692, 0.65539, 0.467999, 0.192916, -0.429285, -0.349553, 0.626268, 0.153931, 0.0643198, 0.292859, 0.156136, -0.064216, 0.0490229, 0.147063, 0.151404, -0.701247, -0.0486219, 0.0359798, -0.307433, -0.254073, -0.0960998, 0.386864, -0.100606, -0.0278402, 0.27646, -0.373706, 0.244237, 0.445031, -0.0736471, 0.681565, -0.361913, 0.107957, -0.0310045, -0.0797901, -0.0512583, -0.560119, 0.0451696, -0.112058, 0.010503, 0.456464, 0.180504, 0.187385, -0.492449, 0.0517042, -0.269497, -0.0741519, -0.134895, -0.102614, 0.0668148, -0.498746, 0.386095, -0.131642, -0.208304, -0.0341324, -0.151889, 0.341949, 0.0420371, -0.116241, 0.440811, -0.108852, 0.134327, 0.0777457, 0.488344, 0.0472591, 0.697291, -0.580174, 0.101828, 0.131381, -0.192425, -0.317998, 0.122801, 0.0694366, 0.21801, -0.0429734, -0.136425, 0.437184, -0.11753, 0.344893, 0.24043, 0.0306901, -0.422333, -0.146097, 0.520181, 0.0972754, -0.186103, -0.0766742, -0.745162, 0.364611, 0.186148, -0.250859, 0.243429, -0.251991, -0.424686, -0.0874009, 0.734041, -0.166786, 0.492071, 0.526676, -0.0864361, 0.288638, 0.0675625, 0.0414367, -0.444774, -0.721337, 0.237171, 0.016888, 0.197957, 0.134051, -0.146543, 0.432, -0.319721, -0.0684138, 0.0339687, -0.104641, 0.232627, 0.212763, 0.559718]}\n"
     ]
    }
   ],
   "source": [
    "word = \"张飞\"\n",
    "\n",
    "\"\"\" 调用词向量表示 \"\"\"\n",
    "print(client.wordEmbedding(word))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'log_id': 7378788256624319542, 'text': '床前明月光', 'items': [{'word': '床', 'prob': 3.85273e-05}, {'word': '前', 'prob': 0.0289018}, {'word': '明月', 'prob': 0.0284406}, {'word': '光', 'prob': 0.808029}], 'ppl': 79.0651}\n"
     ]
    }
   ],
   "source": [
    "text = \"床前明月光\"\n",
    "\n",
    "\"\"\" 调用DNN语言模型 \"\"\"\n",
    "print(client.dnnlm(text))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'log_id': 7320534234156029046, 'error_code': 282004, 'error_msg': 'invalid parameter(s)'}\n"
     ]
    }
   ],
   "source": [
    "word1 = \"北京\"\n",
    "\n",
    "word2 = \"上海\"\n",
    "\n",
    "\"\"\" 调用词义相似度 \"\"\"\n",
    "client.wordSimEmbedding(word1, word2);\n",
    "\n",
    "\"\"\" 如果有可选参数 \"\"\"\n",
    "options = {}\n",
    "options[\"mode\"] = 0\n",
    "\n",
    "#应该是报错了\n",
    "\"\"\" 带参数调用词义相似度 \"\"\"\n",
    "print(client.wordSimEmbedding(word1, word2, options))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "word1 = \"北京\"\n",
    "\n",
    "word2 = \"上海\"\n",
    "\n",
    "\"\"\" 调用词义相似度 \"\"\"\n",
    "client.wordSimEmbedding(word1, word2);\n",
    "\n",
    "\"\"\" 如果有可选参数 \"\"\"\n",
    "options = {}\n",
    "options[\"mode\"] = 0\n",
    "\n",
    "#应该是报错了\n",
    "\"\"\" 带参数调用词义相似度 \"\"\"\n",
    "print(client.wordSimEmbedding(word1, word2, options))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'items': [{'abstract': '三星电脑<span>电池不给力</span>',\n",
       "   'adj': '不给力',\n",
       "   'begin_pos': 8,\n",
       "   'end_pos': 18,\n",
       "   'prop': '电池',\n",
       "   'sentiment': 0}],\n",
       " 'log_id': 408360118580494838}"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text = \"三星电脑电池不给力\"\n",
    "\n",
    "\"\"\" 调用评论观点抽取 \"\"\"\n",
    "client.commentTag(text);\n",
    "\n",
    "\"\"\" 如果有可选参数 \"\"\"\n",
    "options = {}\n",
    "options[\"type\"] = 13\n",
    "\n",
    "\"\"\" 带参数调用评论观点抽取 \"\"\"\n",
    "client.commentTag(text, options)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "text = \"苹果是一家伟大的公司\"\n",
    "\n",
    "\"\"\" 调用情感倾向分析 \"\"\"\n",
    "client.sentimentClassify(text);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'log_id': 5171515067812145622, 'items': [{'score': 0.99775, 'tag': 'iphone'}, {'score': 0.862602, 'tag': '手机'}, {'score': 0.845657, 'tag': '苹果'}, {'score': 0.837886, 'tag': '苹果公司'}, {'score': 0.811601, 'tag': '白苹果'}, {'score': 0.797911, 'tag': '数码'}]}\n"
     ]
    }
   ],
   "source": [
    "title = \"iphone手机出现“白苹果”原因及解决办法，用苹果手机的可以看下\"\n",
    "\n",
    "content = \"如果下面的方法还是没有解决你的问题建议来我们门店看下成都市锦江区红星路三段99号银石广场24层01室。\"\n",
    "\n",
    "\"\"\" 调用文章标签 \"\"\"\n",
    "print(client.keyword(title, content))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'log_id': 8494935512860484758, 'item': {'lv2_tag_list': [{'score': 0.915631, 'tag': '足球'}, {'score': 0.803507, 'tag': '国际足球'}, {'score': 0.77813, 'tag': '英超'}], 'lv1_tag_list': [{'score': 0.830915, 'tag': '体育'}]}}\n"
     ]
    }
   ],
   "source": [
    "title = \"欧洲冠军杯足球赛\"\n",
    "\n",
    "content = \"欧洲冠军联赛是欧洲足球协会联盟主办的年度足球比赛，代表欧洲俱乐部足球最高荣誉和水平，被认为是全世界最高素质、最具影响力以及最高水平的俱乐部赛事，亦是世界上奖金最高的足球赛事和体育赛事之一。\"\n",
    "\n",
    "\"\"\" 调用文章分类 \"\"\"\n",
    "print(client.topic(title, content))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'log_id': 7849450988077375894, 'item': {'vec_fragment': [{'ori_frag': '人工只能公司', 'begin_pos': 10, 'correct_frag': '人工智能公司', 'end_pos': 22}], 'score': 0.797593, 'correct_query': '百度是一家人工智能公司'}, 'text': '百度是一家人工只能公司'}\n"
     ]
    }
   ],
   "source": [
    "text = \"百度是一家人工只能公司\"\n",
    "\n",
    "\"\"\" 调用文本纠错 \"\"\"\n",
    "print(client.ecnet(text))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'items': [{'label': 'optimistic',\n",
       "   'prob': 0.501008,\n",
       "   'replies': ['开心笑一笑'],\n",
       "   'subitems': [{'label': 'happy', 'prob': 0.501008}]},\n",
       "  {'label': 'neutral', 'prob': 0.49872, 'replies': [], 'subitems': []},\n",
       "  {'label': 'pessimistic',\n",
       "   'prob': 0.000272128,\n",
       "   'replies': [],\n",
       "   'subitems': []}],\n",
       " 'log_id': 7597699057387934006,\n",
       " 'text': '本来今天高高兴兴'}"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text = \"本来今天高高兴兴\"\n",
    "\n",
    "\"\"\" 调用对话情绪识别接口 \"\"\"\n",
    "client.emotion(text);\n",
    "\n",
    "\"\"\" 如果有可选参数 \"\"\"\n",
    "options = {}\n",
    "options[\"scene\"] = \"talk\"\n",
    "\n",
    "\"\"\" 带参数调用对话情绪识别接口 \"\"\"\n",
    "client.emotion(text, options)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'log_id': 907337298520412662, 'summary': '麻省理工学院的研究团队为无人机在仓库中使用RFID技术进行库存查找等工作，创造了一种...'}\n"
     ]
    }
   ],
   "source": [
    "content = \"麻省理工学院的研究团队为无人机在仓库中使用RFID技术进行库存查找等工作，创造了一种...\"\n",
    "\n",
    "maxSummaryLen = 300\n",
    "\n",
    "\"\"\" 调用新闻摘要接口 \"\"\"\n",
    "client.newsSummary(content, maxSummaryLen);\n",
    "\n",
    "\"\"\" 如果有可选参数 \"\"\"\n",
    "options = {}\n",
    "options[\"title\"] = \"标题\"\n",
    "\n",
    "\"\"\" 带参数调用新闻摘要接口 \"\"\"\n",
    "print(client.newsSummary(content, maxSummaryLen, options))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# text = \"上海市浦东新区纳贤路701号百度上海研发中心 F4A000 张三\"\n",
    "\n",
    "# 没有\n",
    "# \"\"\" 调用地址识别接口 \"\"\"\n",
    "# # client.address(text)\n",
    "# # client.address(text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
